if lib and not lib.FormatTime then


function lib:FormatTime(d)
	if not d then d = os.sysdate() end
	if type(d) == "table" then
		return string.format("%02d%02d%02d", d.hour, d.min, d.sec)
	end
	local v = {}
	v.sec = round(d % 60)
	v.min = round((d - v.sec) / 60 % 60)
	v.hour = round((d - v.sec - v.min * 60) / 3600 % 24)
	return self:FormatTime(v)
end


function lib:FormatDate(d)
	local inc_year = 0
	if type(d) == "boolean" then inc_year = 1 end
	if not d then d = self:getTradeDate() end
	if type(d) == "table" then
		return string.format("%04d%02d%02d", d.year + inc_year, d.month, d.day), os.date("*t", os.time(d))
	end
	return self:FormatDate(os.date("*t", int(d)))
end


function lib:FormatSysdate(d)
	if not d then d = os.sysdate() end
	if type(d) == "table" then
		return string.format("%04d%02d%02d%02d%02d%02d%03d%03d",
			d.year, d.month, d.day, d.hour or 0, d.min or 0, d.sec or 0, d.ms or 0, d.mcs or 0
		)
	end
	return self:FormatSysdate(os.date("*t", int(d)))
end


function lib:FormatPrice(price, instr, side)
	local str = ""
	if price then
		local instrument = lib:GetInstrument(instr)
		price = self:NormalizePrice(price, instrument, side)
		if instrument then
			if instrument.scale > 0 then
				str = string.format("%." .. instrument.scale .. "f", price)
			else
				str = string.format("%d", int(price))
			end
		else
			str = string.format("%f", price)
			str = string.gsub(str, "0+$", "")
			if "." == string.sub(str, -1, -1) then
				str = string.sub(str, 1, -2)
			end
		end
	end
	return str
end


function lib:FormatBalance(price)
	local str = tostring(int(price))
	str = string.gsub(string.reverse(str), "(%d%d%d)", "%1 ")
	str = string.match(string.reverse(str), "^%s*(.*)")
	str = string.gsub(str, "[^%d ]", "")
	return str
end


end -- of file
